package com.sskj.lib.router.service;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.HttpParams;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.shizhefei.mvc.MVCHelper;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.mvchelper.LoadViewFactory;


@Route(path = "/lib/application")
public class LibService implements IProvider {
    @Override
    public void init(Context context) {
        MVCHelper.setLoadViewFractory(new LoadViewFactory());

        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context1, layout) -> new MaterialHeader(context1));
        HttpParams httpParams = new HttpParams();
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.put("systemType", "android");
        httpParams.put("systemType", "android");
        String id = SPUtil.get(SPConfig.ID, "");
        if (!TextUtils.isEmpty(id)) {
            httpHeaders.put("id", id);
            httpParams.put("id", id);
        }
        String sessionId = SPUtil.get(SPConfig.SESSIONID, "");
        if (!TextUtils.isEmpty(sessionId)) {
            httpHeaders.put(SPConfig.SESSIONID, sessionId);
            httpParams.put(SPConfig.SESSIONID, sessionId);
        }
        String account = SPUtil.get(SPConfig.ACCOUNT, "");
        if (!TextUtils.isEmpty(account)) {
            httpHeaders.put(SPConfig.ACCOUNT, account);
            httpParams.put(SPConfig.ACCOUNT, account);
        }
        String mobile = SPUtil.get(SPConfig.MOBILE, "");
        if (!TextUtils.isEmpty(mobile)) {
            httpHeaders.put(SPConfig.MOBILE, mobile);
            httpParams.put(SPConfig.MOBILE, mobile);
        }
        String token = SPUtil.get(SPConfig.TOKEN, "");
        if (!TextUtils.isEmpty(token)) {
            httpHeaders.put("token", token);
            httpParams.put("token", token);
        }
        OkGo.getInstance().addCommonParams(httpParams);
        OkGo.getInstance().addCommonHeaders(httpHeaders);
    }
}
